<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
	<title>按品规添加药品</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>按品规添加药品</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">采购项目管理</a></li>
            <li class="active"><a href="#">按品规添加药品</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                    <div class="form-group form-group-xs">
                     <label>品规编号：</label>
                        <input class="form-control" type="text" id="qualityspecCode" placeholder="品规编码" />
                    </div>
                     <div class="form-group form-group-xs">
                        <label>通用名：</label>
                        <input class="form-control" type="text" id="qualityspecName" placeholder="通用名" />
                    </div>
                    
                    <button type="button" class="btn btn-success btn-sm" onclick="search()">查&nbsp;询</button>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
	        <a href="javascript:submitDrugTOProjs();" class="btn btn-default btn-sm">添&nbsp;加</a>
	          <a href="javascript:history.go(-1)" class="btn btn-default btn-sm back" >返&nbsp;回</a>
         <!--   <a href="toBidProjectCheckList.html" class="btn btn-default btn-sm" >返回</a> -->
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
    //查询
	function search() {
		var qualityspecCode = $("#qualityspecCode").val();
		var qualityspecName = $("#qualityspecName").val();
		$("#gridlist").jqGrid("clearGridData");
			$("#gridlist").jqGrid('setGridParam',{  
			url:"${ctx}/bidProject/getDrugqualityspecDataList.html?projId=${projId}",
			mtype: "POST",
	        datatype:'json',
	        postData:{"qualityspecCode":qualityspecCode, "qualityspecName":qualityspecName},
	        page : 1
	    }).trigger("reloadGrid"); //重新载入  
	}
        $(function () {
            $("#gridlist").jqGrid({
                url: "${ctx}/bidProject/getDrugqualityspecDataList.html?projId=${projId}",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['drugcatalogId','qualityspecId','目录编号','目录名称','品规编号', '通用名', '剂型','规格'],
                colModel: [
					{ name: 'drugcatalogId', width: 100,hidden:true , align:"center" ,sortable: false},
					{ name: 'qualityspecId', width: 100,hidden:true , align:"center" ,sortable: false},
					{ name: 'drugcatalogCode', width: 100 , align:"center",sortable: false},
					{ name: 'drugcatalogName', width: 100 , align:"center",sortable: false},
					{ name: 'qualityspecCode', width: 100 , align:"center",sortable: false},
                    { name: 'qualityspecName', width: 100 , align:"center" ,sortable: false},
                    { name: 'specName', width: 100 , align:"center" ,sortable: false},
                    { name: 'formName', width: 100 , align:"center" ,sortable: false}
                ],
                
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "${name} - 未添加药品",
                //序号宽度自动变化
                gridComplete:function(){     
                    var page = $("#gridlist").jqGrid('getGridParam','page');
                    var rows = $('#gridlist').getGridParam("rowNum");
                    var maxnum = (rows*page).toString();
                    var len = (maxnum.length)*10;
                    $('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                    $('#gridlist_rn').css('width',len+'px');
                },
                jsonReader: {
                    repeatitems: false,
                    id: "qualityspecId"
                },
                loadComplete: function (data) { //完成服务器请求后，回调函数
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });

		
        //导入
    	function submitDrugTOProj(list){ 
    		$.HN.message.confirm('确定要添加吗？', '', '').on(function (e) {
	               if (e) {
           	$.ajax({
				type:"POST",
				url:"${ctx}/bidProject/importDrugByCatalogDetail.html",
				data:{"qualityspecId":qualityspecId,"projId":projId},
				dataType:"json",
				success:function(returnData){
					if (returnData.success == true) {
						$("#gridlist").jqGrid("clearGridData");
	    				$("#gridlist").jqGrid().trigger("reloadGrid");
	    				$.HN.message.alert("添加成功！", "消息", "success");
	    			} else {
	    				$.HN.message.alert("添加失败！", "消息", "error");
	    			}
				}
			});
	               }
          	 });
        }
    	//批量导入
        function submitDrugTOProjs() {
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.HN.message.alert("请选择要操作的行！", "消息", "error");
                return;
            }
            $.HN.message.confirm("确定添加吗？", '', '').on(function (e) {
       		 if(e){
            var list = [];
            for (var i=0; i<rowIds.length; i++) {
           	 var rowdata = $("#gridlist").jqGrid(
							'getRowData', rowIds[i]);
                list.push({"qualityspecId":rowdata.qualityspecId,"drugcatalogId":rowdata.drugcatalogId});
            }
            $.post("${ctx}/bidProject/importDrugqualityspec.html", {
                "array" : json.jsonToString(list),"projId":"${projId}"
            }, function(result) {
                if (result) {
                    $.HN.message.alert("操作成功！", "消息", "success");
                    $("#gridlist").jqGrid('setGridParam',{ 
                    	
            	        datatype:'json'
            	    }).trigger("reloadGrid");
                } else {
                    $.HN.message.alert("操作失败！", "消息", "error");
                }
            }, "json")
		      }
				 
			 });
        }
    	
    </script>
</body>
</html>